Parsing Page Ranges
You can install an override function for thegxParsePageRange
message, which allows you to check the validity of page numbers that the user selects in the Print dialog box. You must override this message if you allow the user to specify application-specific page ranges, such as "Chapter 5."Listing 3-28 shows a function,
MyPrintDialog
, which is called in response to the user choosing the Print menu item from the File menu. TheMyPrintDialog
function installs an override for thegxParsePageRange
message, sets up a default page range, and calls theGXPrintDialog
function to display the dialog box with the default page range. After the pages have been printed, or if an error occurred while setting up the default page range, the override function for thegxParsePageRange
message is removed.Listing 3-28 Installing an override function for the
gxParsePageRange
message
OSErr MyPrintDialog(MyDocumentPtr myDocument) { OSErr err; gxDialogResult result; gxEditMenuRecord editMenuRec; /* Install an override function to parse page ranges. */ GXInstallApplicationOverride(myDocument->documentJob, gxParsePageRange, MyParsePageRangeOverride); . . . err = MySetupDefaultPageRange(myDocument); /* not shown */ nrequire(err, CouldNotConfigurePageRange); /* Display the Print dialog box. If there are no errors and the user selects the "OK" button, call a printing routine to output the pages. */ result = GXJobPrintDialog(myDocument->documentJob, &editMenuRec); err = GXGetJobError(myDocument->documentJob); if ((err == noErr) && (result == gxOKSelected)) err = MyPrintDocument(myDocument); /* not shown */ . . . /* Remove the parse page range override function. */ CouldNotConfigurePageRange: GXInstallApplicationOverride(myDocument->documentJob, gxParsePageRange, nil); return err; }The MySetupDefaultPageRange function that sets up a page range is not shown. For examples of setting up page ranges, see "Specifying Page Ranges in the Job Collection" on page 3-33. The MyPrintDocument function that prints pages is not shown. For information about printing pages, see the chapter "Core Printing Features" in this book.Listing 3-29 shows the override function, MyParsePageRangeOverride, which calls another function, MyPageRangeValidityCheck, to validate the page range.
Listing 3-29 Override function for the
gxParsePageRange
message
OSErr MyParsePageRangeOverride(StringPtr fromString, StringPtr toString, gxParsePageRangeResult *result) { /* Determine if the "To page" and "From page" strings are valid. If not, the MyPageRangeValidityCheck routine returns gxRangeBadFromValue or gxRangeBadToValue. Otherwise it will return gxRangeParsed. */ if (*result == gxRangeNotParsed) *result = MyPageRangeValidityCheck(fromString, toString); return noErr; }The MyPageRangeValidityCheck function is not shown. It returns gxRangeParsed if the page range is valid, otherwise it returns gxRangeBadFromValue if the From value is invalid or gxRangeBadToValue if the To value is invalid. For information about parse page range constants, see "The Panel Setup Structure" on page 3-101.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help